﻿<!DOCTYPE html>
<html>
<head>
    <title>商品车</title>
</head>
<body>
    <div>
        <section data-role="page" data-theme="b" id="goodscard_main">
            <div style="padding:5px;" id="goodscard_content">
                <div class="detail-main">
                    <div style="text-align:center;font-size:12px;display:none;" runat="server" id="msg"><img src="images/history-consumption.png"/><span id="msgText">购物车中暂无商品</span></div>
                    <ul data-role="listview" data-theme="d">
                        <asp:Repeater runat="server" ID="rptGoodsCard">
                            <ItemTemplate>
                                <li>
                                    <a href="#">
                                        <div class="detail_row">
                	                        <!--left-->
                                            <div class="row_item row_item-left">
                                                <img src="<%#Eval("MicroGoodsPicture") %>"/>
                                            </div>
                                            <!--right-->
                                            <div class="row_item row_item-right">
                                                <strong style="font-size:14px;"><%#Eval("MicroGoodsName")%></strong>
                                                <span style="margin-top:5px;display:block;">会员价格：<span class="discountPrice"><%#Convert.ToDecimal(Eval("MicroPrice")).ToString("0.00")%></span>元</span>
                                                <span style="margin-top:5px;display:block;">小计金额：<span class="discountPrice Subtotal"><%#Convert.ToDecimal(Eval("Subtotal")).ToString("0.00")%></span>元</span>
                                                <div>
                                                    <span>购买数量：</span>
                                                    <span class="minus" MicroGoodsID="<%#Eval("MicroGoodsID") %>"><img src="images/minus.png" /></span>
                                                    <span class="number"><%#Eval("ConvertNumber") %></span>
                                                    <span class="plus" MicroGoodsID="<%#Eval("MicroGoodsID") %>"><img src="images/plus.png" /></span>
                                                </div>
                                            </div>
                                                <!--right end-->
                                        </div>
                                    </a>
                                    <a href="#" data-icon="delete" class="deleteGood" MicroGoodsID="<%#Eval("MicroGoodsID") %>"></a>
                                </li>
                            </ItemTemplate>
                        </asp:Repeater>
                    </ul>
                    
                    <span id="total" runat="server"></span>
                </div>

               <a href="#goodorders" data-load="goodorders.aspx" data-role="button" data-theme="a" id="aApplicationGoodsOrder">提交订单</a>

            </div>
            <script type="text/javascript" src="../Scripts/Module/Common/Common.js" ></script>
            <script type="text/javascript">
                if (getCookie("goodlist") == null || getCookie("goodlist") == "") { $("#aApplicationGoodsOrder").css("display", "none"); }
                $("span[class='minus'],span[class='plus']").click(function () {
                    var type = $(this).attr("class");
                    var number = parseInt($(this).siblings("[class='number']").text());
                    if (type == "plus") { number++; } else { number <= 1 ? 1 : number--; }
                    $(this).siblings("[class='number']").text(number);

                    //更新小计金额
                    var Point = $(this).parent("div").siblings("span").children("span[class='discountPrice']").text();
                    var Subtotal = $(this).parent("div").siblings("span").children("span[class='discountPrice Subtotal']")
                    Subtotal.text(accMul(parseFloat(Point), number));

                    //更新应付总金额
                    UpDateTotal();

                    //更新localStorage对象
                    var strKey = "";
                    var getData = "";
                    var MicroGoodsID = $(this).attr("MicroGoodsID");
                    for (var i = 0; i < localStorage.length; i++) {
                        strKey = localStorage.key(i);
                        if (strKey.substring(0, 5) == "good_") {
                            getData = JSON.parse(xxl.xd.getValue(strKey));
                            if (getData.MicroGoodsID == MicroGoodsID) { break; } else { getData = ""; }
                        }
                    }
                    if (getData != "") {//编辑
                        getData.ConvertNumber = number;
                        xxl.xd.setValue(getData.Type, JSON.stringify(getData));
                    }

                    //更新Cookie
                    UpDateCookie();
                })

                $("a[class=deleteGood]").click(function () {
                    var MicroGoodsID = $(this).attr("MicroGoodsID");
                    if (confirm("确定要删除吗？")) {
                        $(this).parent("li").remove();
                        //更新应付总积分
                        UpDateTotal();
                        //更新localStorage对象
                        var strKey = "";
                        var getData = "";
                        for (var i = 0; i < localStorage.length; i++) {
                            strKey = localStorage.key(i);
                            if (strKey.substring(0, 5) == "good_") {
                                getData = JSON.parse(xxl.xd.getValue(strKey));
                                if (getData.MicroGoodsID == MicroGoodsID) { localStorage.removeItem(getData.Type); } else { getData = ""; }
                            }
                        }
                        //更新Cookie
                        UpDateCookie();
                        //显示信息
                        showMsg();
                    }
                })

                //更新应付总金额
                function UpDateTotal() {
                    var total = 0;
                    $("span[class='discountPrice Subtotal']").each(function () {
                        total += parseFloat($(this).text());
                    })
                    $("#total").text("应付总金额：￥" + parseFloat(total).toFixed(2));
                }
                //更新Cookie
                function UpDateCookie() {
                    var cookieStr = "";
                    for (var i = 0; i < localStorage.length; i++) {
                        strKey = localStorage.key(i);
                        if (strKey.substring(0, 5) == "good_") {
                            getData = JSON.parse(xxl.xd.getValue(strKey));
                            cookieStr += getData.MicroGoodsID + ',' + getData.ConvertNumber + '|';
                        }
                    }
                    setCookie("goodlist", cookieStr);
                }

                function showMsg() {
                    var hasGood = false;
                    for (var i = 0; i < localStorage.length; i++) {
                        if (strKey.substring(0, 5) == "good_") { hasGood = true; break; }
                    }
                    if (!hasGood) {
                        $("#aApplicationGoodsOrder,#total").css("display", "none");
                        $("#msgText").text("购物车中商品已清空");
                        $("#msg").css("display", "");
                    }
                }
            </script>

        <footer data-role="footer" data-position="fixed" id="goodscard_footer">
            <div data-role="navbar" id="nav-glyphish-example">
                <ul>
                    <li><a href="#index" data-icon="custom" id="site" >商家网站</a></li>
                    <li><a href="#goodlist" data-load="goodlist.aspx" data-icon="custom" id="buy" class="ui-btn-active">商品购买</a></li>
                    <li><a href="#membershipcard" data-load="membershipcard.aspx" data-icon="custom"  id="card">会员卡</a></li>
                    <li><a href="#giftlist" data-load="giftlist.aspx" data-icon="custom" id="convert">积分兑换</a></li>
                </ul>
            </div>
        </footer>
        </section>
    </div>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="goodscard.aspx.cs" Inherits="goodscard" EnableViewState="false" %>